﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using GD.ModelContest.Common;
using GD.ModelContest.Model;
using GD.ModelContest.Service;

namespace GD.ModelContest.Web
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataBind_NewsList1();
                DataBind_NewsList2();
            }
        }

        protected void DataBind_NewsList1()
        {
            this.rpNewsList1.DataSource = ServiceLocator.INewsService.GetNewsCollection(1,6);
            this.rpNewsList1.DataBind();
        }
        protected void DataBind_NewsList2()
        {
            this.rpNewsList2.DataSource = ServiceLocator.INewsService.GetNewsCollection(2, 6);
            this.rpNewsList2.DataBind();
        }

        protected void rpNewsList1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                mc_news mcNews = (mc_news)e.Item.DataItem;
                HyperLink hlTitle = (HyperLink)e.Item.FindControl("hlTitle");
                hlTitle.Text = mcNews.title;
                hlTitle.NavigateUrl = string.Format("NewsView.aspx?NewsId={0}", mcNews.newsId);
            }
        }

        protected void rpNewsList2_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                mc_news mcNews = (mc_news)e.Item.DataItem;
                HyperLink hlTitle = (HyperLink)e.Item.FindControl("hlTitle");
                hlTitle.Text = mcNews.title;
                hlTitle.NavigateUrl = string.Format("NewsView.aspx?NewsId={0}", mcNews.newsId);
            }
        }
    }
}
